package mumu.android.lib.view;

import mumu.android.R;
import mumu.android.lib.tool.MLog;
import android.app.Dialog;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class NormalDialogFragment extends DialogFragment {

	static NormalDialogFragment instance;

	public static NormalDialogFragment getInstance() {
		if (instance == null) {
			instance = new NormalDialogFragment();
		}
		return instance;
	}

	@Override
	public void dismiss() {
		super.dismiss();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		MLog.d("dds", "onCreate");
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onDestroyView() {
		MLog.d("dds", "onDestroyView");
		super.onDestroyView();
	}

	// @Override
	// public View onCreateView(LayoutInflater inflater, ViewGroup container,
	// Bundle savedInstanceState) {
	// getDialog().setCanceledOnTouchOutside(true);
	// Window dialogWindow = getDialog().getWindow();
	// WindowManager.LayoutParams lp = dialogWindow.getAttributes();
	// dialogWindow.setGravity(Gravity.RIGHT | Gravity.TOP);
	// lp.y = 150;
	// lp.x = 150;
	// dialogWindow.setAttributes(lp);
	// setStyle(R.style.dialog,R.style.dialog);
	// return inflater.inflate(R.layout.dialog_listview, null);
	//
	// }

	Dialog dialog;
	TextView txt;

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		MLog.d("dds", "onCreateDialog");
		if (dialog == null) {
			dialog = new Dialog(getActivity(), R.style.dialog);
			LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
			View view = layoutInflater.inflate(R.layout.dialog_listview, null);
			view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
			dialog.setContentView(R.layout.dialog_listview);
			dialog.setCanceledOnTouchOutside(true);
			Window dialogWindow = dialog.getWindow();
			WindowManager.LayoutParams lp = dialogWindow.getAttributes();
			dialogWindow.setGravity(Gravity.RIGHT | Gravity.TOP);
			lp.y = 150;
			lp.x = 150;
			dialogWindow.setAttributes(lp);
			txt = (TextView) dialog.findViewById(R.id_lvdialog.txt_top);
			txt.setText("哈哈");
		} else {
			txt.setText("Wuhan");
		}
		return dialog;
		// return super.onCreateDialog(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		MLog.d("dds", "onCreateView");
		txt = (TextView) dialog.findViewById(R.id_lvdialog.txt_top);
		txt.setText("哈哈22");
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		MLog.d("dds", "onConfigurationChanged");
		super.onConfigurationChanged(newConfig);
	}

	@Override
	public void onDestroy() {
		MLog.d("dds", "onDestroy");
		super.onDestroy();
	}

	@Override
	public void onPause() {
		MLog.d("dds", "onPause");
		super.onPause();
	}

	@Override
	public void onResume() {
		MLog.d("dds", "onResume");
		super.onResume();
	}

}
